﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Web;
using System.Xml;

using umbraco.cms.presentation.Trees;
using umbraco.interfaces;

namespace Bodenko.Umbraco.Tree.RobotsTxt
{
	public class RobotsTxtTree : BaseTree
	{
		public RobotsTxtTree(String applicaton) : base(applicaton) { }

		protected override void CreateRootNode(ref XmlTreeNode rootNode)
		{
			rootNode.Action = "javascript:openRobotsTxtEditor();";
			rootNode.Text = "Robots.txt";
			rootNode.Icon = "../../robots-txt/robot.png";
			rootNode.OpenIcon = rootNode.Icon;
			rootNode.NodeID = "init";
			rootNode.NodeType = String.Concat(rootNode.NodeID, this.TreeAlias);
			rootNode.Menu = new List<IAction>();
			rootNode.HasChildren = false;
		}

		public override void Render(ref XmlTree tree)
		{
			// nothing happens here (yet)
		}

		public override void RenderJS(ref StringBuilder Javascript)
		{
			Javascript.Append(@"
				function openRobotsTxtEditor() { parent.right.document.location.href = 'robots-txt/editRobotsTxtFile.aspx'; }
			");
		}
	}
}
